#include "ascan.h"

namespace eintik::data::scan {

    std::vector<AScan::Coord> AScan::frame_a(int id)
    {
        auto cnt_p = eintik::property::cnt_points();
        auto cnt_beam = eintik::property::cnt_beam();
        auto range = eintik::property::signal_range();
        if (cnt_beam * cnt_p != frame.size()) {
            return {};
        }
        if (id < 0 || id >= cnt_beam) {
            return {};
        }
        auto b = frame.data() + id * cnt_p;
        std::vector<Coord> ret;
        ret.reserve(cnt_p);
        for (auto i = 0; i < cnt_p; i++) {
            ret.push_back({range / cnt_p * i, b[i] / ratio});
        }
        return ret;
    }

    std::vector<AScan::Coord> AScan::frame_a_abs(int id)
    {
        auto cnt_p = eintik::property::cnt_points();
        auto cnt_beam = eintik::property::cnt_beam();
        auto range = eintik::property::signal_range();
        if (cnt_beam * cnt_p != frame.size()) {
            return {};
        }
        if (id < 0 || id >= cnt_beam) {
            return {};
        }
        auto b = frame.data() + id * cnt_p;
        std::vector<Coord> ret;
        ret.reserve(cnt_p);
        for (auto i = 0; i < cnt_p; i++) {
            ret.push_back({range / cnt_p * i, std::abs(b[i] / ratio)});
        }
        return ret;
    }

    std::vector<int16_t> AScan::frame_a_raw(int id)
    {
        auto cnt_p = eintik::property::cnt_points();
        auto cnt_beam = eintik::property::cnt_beam();
        auto range = eintik::property::signal_range();
        if (cnt_beam * cnt_p != frame.size()) {
            return {};
        }
        if (id < 0 || id >= cnt_beam) {
            return {};
        }
        auto b = frame.data() + id * cnt_p;
        return std::vector<int16_t>(b, b + cnt_p);
    }
}